package com.ruoyi.web.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SoftwareMdcode;
import com.ruoyi.system.service.ISoftwareMdcodeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 软件管理Controller
 *
 * @author ruoyi
 * @date 2022-08-17
 */
@Controller
@RequestMapping("/system/mdcode")
public class SoftwareMdcodeController extends BaseController {
    private String prefix = "system/mdcode";

    @Autowired
    private ISoftwareMdcodeService softwareMdcodeService;

    @RequiresPermissions("system:mdcode:view")
    @GetMapping()
    public String mdcode() {
        return prefix + "/mdcode";
    }

    /**
     * 查询软件管理列表
     */
    @RequiresPermissions("system:mdcode:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SoftwareMdcode softwareMdcode) {
        startPage();
        List<SoftwareMdcode> list = softwareMdcodeService.selectSoftwareMdcodeList(softwareMdcode);
        return getDataTable(list);
    }

    /**
     * 导出软件管理列表
     */
    @RequiresPermissions("system:mdcode:export")
    @Log(title = "软件管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SoftwareMdcode softwareMdcode) {
        List<SoftwareMdcode> list = softwareMdcodeService.selectSoftwareMdcodeList(softwareMdcode);
        ExcelUtil<SoftwareMdcode> util = new ExcelUtil<SoftwareMdcode>(SoftwareMdcode.class);
        return util.exportExcel(list, "软件管理数据");
    }

    /**
     * 新增软件管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存软件管理
     */
    @RequiresPermissions("system:mdcode:add")
    @Log(title = "软件管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SoftwareMdcode softwareMdcode) {
        return toAjax(softwareMdcodeService.insertSoftwareMdcode(softwareMdcode));
    }

    /**
     * 修改软件管理
     */
    @RequiresPermissions("system:mdcode:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        SoftwareMdcode softwareMdcode = softwareMdcodeService.selectSoftwareMdcodeById(id);
        mmap.put("softwareMdcode", softwareMdcode);
        return prefix + "/edit";
    }

    /**
     * 修改保存软件管理
     */
    @RequiresPermissions("system:mdcode:edit")
    @Log(title = "软件管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SoftwareMdcode softwareMdcode) {
        return toAjax(softwareMdcodeService.updateSoftwareMdcode(softwareMdcode));
    }

    /**
     * 删除软件管理
     */
    @RequiresPermissions("system:mdcode:remove")
    @Log(title = "软件管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(softwareMdcodeService.deleteSoftwareMdcodeByIds(ids));
    }


    @PostMapping("/getitem")
    @ResponseBody
    public AjaxResult getsoftware(SoftwareMdcode softwareMdcode) {
        return success(softwareMdcodeService.MyselectSoftwareMdcodeList(softwareMdcode));
    }

}
